package abstraction;

import implementor.Filter;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;

public abstract class Image {
    protected Filter filter;
    protected String filePath;
    protected Mat image;
    
    public Image(String filePath) {
        this.filePath = filePath;
        this.image = Imgcodecs.imread(filePath);
        if (this.image.empty()) {
            System.out.println("无法加载图像: " + filePath);
        }
    }
    /**
     * 设置滤镜
     * @param filter 要应用的滤镜
     */
    public void setFilter(Filter filter) {
        this.filter = filter;
    }
    /**
     * 应用滤镜并保存图像
     * @param outputPath 输出路径
     */
    public void processAndSave(String outputPath) {
        if (filter == null) {
            System.out.println("未设置滤镜，无法处理图像");
            return;
        }
        
        System.out.println("正在处理" + getType() + "图像，应用" + filter.getName() + "滤镜...");
        Mat processedImage = filter.apply(image);
        
        boolean success = Imgcodecs.imwrite(outputPath, processedImage);
        if (success) {
            System.out.println("图像已保存到: " + outputPath);
        } else {
            System.out.println("保存图像失败");
        }
    }
    
    /**
     * 获取图像类型
     * @return 图像类型名称
     */
    public abstract String getType();
    
    /**
     * 获取图像的特定信息
     * @return 图像信息
     */
    public abstract String getInfo();
}